package com.augurit.gzcgwsp.hwgz.convert;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.dozer.DozerBeanMapper;

import com.augurit.common.util.lang.DateUtils;
import com.augurit.gzcgwsp.hwgz.entity.YwHwShSqb;
import com.augurit.gzcgwsp.hwgz.web.form.YwHwShSqbForm;
import com.augurit.gzcgwsp.sendNotice.exchangedatatofx.entity.YwHwShSqbForFx;
import com.augurit.gzcgwsp.ywcmn.web.form.YwComQyxxForm;

public class YwHwShSqbConvertor {
    public static YwHwShSqbForm convertVoToForm(YwHwShSqb entity) {
        if (entity == null) return null;
        YwHwShSqbForm form = new DozerBeanMapper().map(entity, YwHwShSqbForm.class);
            
        form.setAcceptNo2(entity.getAcceptNo());
        form.setCbyw2(entity.getCbyw());
        form.setCbyw3(entity.getCbyw());
        form.setCbyw4(entity.getCbyw());
        
        form.setSjr2(entity.getSjr());
        form.setSqdw2(entity.getSqdw());
        //form.setSqrq2(entity.getSqrq());
        if(entity.getSqrq() != null){
	        form.setSqrq3(DateUtils.dateTimeToString(entity.getSqrq(), DateUtils.YEAR_MOUTH_DAY_));
	        form.setSqrq4(DateUtils.dateTimeToString(entity.getSqrq(), DateUtils.YEAR_MOUTH_DAY_));
        }else{
        	form.setSqrq3(DateUtils.dateTimeToString(new Date(), DateUtils.YEAR_MOUTH_DAY_));
            form.setSqrq4(DateUtils.dateTimeToString(new Date(), DateUtils.YEAR_MOUTH_DAY_));
        }
        form.setLxr2(entity.getJbrxm());
        form.setCurDate(DateUtils.dateTimeToString(new Date(), DateUtils.YEAR_MOUTH_DAY_));
        form.setCurDate2(form.getCurDate());
        form.setCurDate3(form.getCurDate());
        form.setGgxsStr(entity.getGgxsStr());
        form.setStartyear(entity.getStartyear());
        form.setStartmonth(entity.getStartmonth());
        form.setStartday(entity.getStartday());
        form.setEndyear(entity.getEndyear());
        form.setEndmonth(entity.getEndmonth());
        form.setEndday(entity.getEndday());
        form.setPrintyear(entity.getPrintyear());
        form.setPrintmonth(entity.getPrintmonth());
        form.setPrintday(entity.getPrintday());
        form.setBz(entity.getBz());
        form.setSzzh(entity.getSzzh());
        return form;
    }
    
    public static void convertFormToQyxxForm(YwHwShSqbForm form, YwComQyxxForm qyxxForm) {
        if (form == null) return;
        if (qyxxForm == null) qyxxForm = new YwComQyxxForm();

        new DozerBeanMapper().map(form, qyxxForm);
        qyxxForm.setId(form.getQyid());
    }

    public static void convertQyxxFormToForm(YwComQyxxForm qyxxForm, YwHwShSqbForm form) {
        if (qyxxForm == null) return;
        if (form == null) form = new YwHwShSqbForm();
        
        new DozerBeanMapper().map(qyxxForm, form);
        form.setQyid(qyxxForm.getId());
    }
    
    public static void convertFormToVo(YwHwShSqbForm form, YwHwShSqb entity) {
        if (form == null) return;
        if (entity == null) entity = new YwHwShSqb();
        
        new DozerBeanMapper().map(form, entity);
    }
    
    public static List<YwHwShSqbForm> convertVoListToFormList(List<YwHwShSqb> ywHwShSqbList) {
        if(ywHwShSqbList != null && ywHwShSqbList.size() > 0) {
            List<YwHwShSqbForm> ywHwShSqbFormList = new ArrayList();
            for(int i=0; i<ywHwShSqbList.size(); i++) {
                ywHwShSqbFormList.add(convertVoToForm(ywHwShSqbList.get(i)));
            }
            return ywHwShSqbFormList;
        }
        return null;
    }
    
    public static List<YwHwShSqb> convertFormListToVoList(List<YwHwShSqbForm> ywHwShSqbFormList) {
        if(ywHwShSqbFormList != null && ywHwShSqbFormList.size() > 0) {
            List<YwHwShSqb> ywHwShSqbList = new ArrayList();
            for(int i=0; i<ywHwShSqbFormList.size(); i++) {
                YwHwShSqb ywHwShSqb = new YwHwShSqb();
                convertFormToVo(ywHwShSqbFormList.get(i), ywHwShSqb);
                ywHwShSqbList.add(ywHwShSqb);
            }
            return ywHwShSqbList;
        }
        return null;
    }
    
    public static void convertFormToYwHwShSqbForFx(YwHwShSqbForm form, YwHwShSqbForFx entity) {
        if (form == null) return;
        if (entity == null) entity = new YwHwShSqbForFx();
        if(StringUtils.isNotEmpty(form.getQylx())){
        	entity.setType(form.getQylx());
        }
        if(StringUtils.isNotEmpty(form.getFrxm())){
        	entity.setFr(form.getFrxm());
        }
        if(StringUtils.isNotEmpty(form.getZsbh())){
        	entity.setYyzzh(form.getZsbh());
        }
        if(StringUtils.isNotEmpty(form.getJbrxm())){
        	entity.setJbr(form.getJbrxm());
        }
        new DozerBeanMapper().map(form, entity);
    }
}